home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / crmv1.91t / developer / oberon / crm.mod next >
Text File  |  1995-03-09  |  7KB  |  202 lines

  1. (*---------------------------------------------------------------------------
  2.  :Program.     CrM
  3.  :Contents.    Interface to Thomas Schwarz's CrM.library V4.0
  4.  :Author.      Alexander Ehlert ( C version by Thomas Schwarz )
  5.  :Address.     Beethovenstr. 59/3  72458 Albstadt
  6.  :Copyright.   refer to conditions of crm.library
  7.  :Language.    Oberon-2
  8.  :Translator.  Amiga-Oberon V3.10
  9.  :History.     V1.0 translated from C to Oberon
  10.  :Bugs.        none, I hope !
  11.  :Remarks.     Thanx to Tom for this library
  12.  :Remarks.     -> and for registering me :-)
  13.  --------------------------------------------------------------------------*)
  14. MODULE CrM;
  15. IMPORT u  : Utility,
  16.        e  : Exec,
  17.        D  : Dos,
  18.        S  : SYSTEM,
  19.        i  : Intuition;
  20.  
  21. CONST
  22.   CrMName*    = "CrM.library";
  23.   CrMVersion* = 4;
  24.  
  25.   (*************************************
  26.    ** Result Codes of CheckCrunched()
  27.    ** and Symbols for the CMAlgo Tag
  28.    *************************************)
  29.  
  30.   (* Crunchmode Flags *)
  31.  
  32.   Normal*   =   0;
  33.   LZH*      =   1;
  34.   Sample*   =   4;
  35.   PW*       =   5;
  36.   Overlay*  =   8;       (* only for    *)
  37.   LEDFlash* =   9;       (* CMAlgo Tag! *)
  38.  
  39.  
  40.   (* Use this mask to get the crunch algorithm without any other flags: *)
  41.   AlgoMask  =  0FH;    (* but please not in OBERON ;-) *)
  42.  
  43.   (**********************************
  44.    ** Action Codes for ProcessPW()
  45.    **********************************)
  46.  
  47.   AddPW*     =  1;
  48.   RemovePW*  =  2;
  49.   RemoveAll* =  3;
  50.  
  51.   (**********************************
  52.    ** Action Codes for CryptData()
  53.    **********************************)
  54.  
  55.   EnCrypt*   =  4;
  56.   DeCrypt*   =  5;
  57.  
  58.   (********************************************
  59.    ** Action Codes for ProcessCrunchStruct()
  60.    ********************************************)
  61.  
  62.   AllocStruct* = 6;
  63.   FreeStruct*  = 7;
  64.  
  65.   (************************************
  66.    ** Tags for ProcessCrunchStruct()
  67.    ************************************)
  68.  
  69.   CMTagBase*  = u.user;
  70.   CMAlgo*     = CMTagBase+1;          (* default: LZH *)
  71.   CMOffset*   = CMTagBase+2;          (* default: 07FFEH *)
  72.   CMHuffSize* = CMTagBase+3;          (* default: 16 *)
  73.  
  74.   (**************
  75.    * Data Header
  76.    **************)
  77.  
  78. TYPE
  79.   DataHeaderPtr* = UNTRACED POINTER TO DataHeader;
  80.   DataHeader* = STRUCT
  81.                  ID-          : LONGINT; (* ULONG *)
  82.                  MinSecDist-  : INTEGER; (* WORD  *)
  83.                  OriginalLen- : LONGINT; (* ULONG *)
  84.                  CrunchedLen- : LONGINT; (* ULONG *)
  85.                END;
  86.  
  87.  
  88.   (***************
  89.    * CurrentStats
  90.    ***************)
  91.  
  92.   CurrentStatsPtr* = UNTRACED POINTER TO CurrentStats;
  93.   CurrentStats* = STRUCT
  94.                     ToGo- : LONGINT; (* ULONG *)
  95.                     Len-  : LONGINT;
  96.                   END;
  97.  
  98.   (********************
  99.    ** CrunchStruct(ure)
  100.    ********************)
  101.  
  102.   CrunchStructPtr* = UNTRACED POINTER TO CrunchStruct;
  103.   CrunchStruct* = STRUCT
  104.                     Src*         : e.APTR;        (* Source Start *)
  105.                     SrcLen*      : LONGINT;       (* Source Len *)
  106.                     Dest*        : e.APTR;        (* Destination Start *)
  107.                     DestLen*     : LONGINT;       (* Destination Len (maximum) *)
  108.                     DataHdr*     : DataHeaderPtr; (* DataHeader *)
  109.                     DisplayHook* : u.HookPtr;     (* Hook to display ToGo/Gain Counters *)
  110.  
  111.  (* Registers hold these values when the Hook is called:                  *)
  112.  (* a0:struct Hook*  a2:struct cmCrunchStruct*  a1:struct cmCurrentStats  *)
  113.  (* you have to return TRUE/FALSE in d0 to continue/abort crunching!      *)
  114.  
  115.                     DisplayStep* : INTEGER;       (* time between 2 calls to the Hook *)
  116.    (******** readonly: ********)
  117.                     Offset-      : INTEGER;       (* desired Offset *)
  118.                     HuffSize-    : INTEGER;       (* HuffLen in KBytes *)
  119.                     Algo-        : SET;           (* desired Packalgorithm *)
  120.                     MaxOffset-   : LONGINT;       (* biggest possible Offset (Buffer allocated) *)
  121.                     RealOffset-  : LONGINT;       (* currently used Offset *)
  122.                     MinSecDist-  : LONGINT;       (* MinSecDist for packed Data *)
  123.                     CrunchedLen- : LONGINT;       (* Length of crunched Data at cmcr_Dest *)
  124.    (******** private: ********)
  125.                     HuffTabs-    : LONGINT;
  126.                     HuffBuf-     : LONGINT;
  127.                     HuffLen-     : LONGINT;
  128.                     SpeedLen-    : LONGINT;
  129.                     SpeedTab-    : LONGINT;
  130.                     MegaSpeedTab-: LONGINT;
  131.  
  132.                     QuitFlag-    : CHAR;          (* readonly: reason for failure *)
  133.                     OverlayFlag- : BOOLEAN;
  134.                     LEDFlashFlag-: BOOLEAN;
  135.                     Pad-         : SHORTINT;
  136.    (* CrunchStruct continues here, but LEAVE YOUR HANDS OFF!!! *)
  137.                   END;(* CrunchStruct *)
  138.      
  139. VAR
  140.   CrMBase : e.LibraryPtr;
  141.  
  142. PROCEDURE CheckCrunched* {CrMBase,-42} (DataHeader{8} : DataHeader):SET;
  143.  
  144. PROCEDURE CrunchData* {CrMBase,-72} (CrunchStruct{8} : CrunchStructPtr):LONGINT;
  145.  
  146. PROCEDURE CryptData* {CrMBase,-60} (DataHeader{8} : DataHeaderPtr;
  147.                                     data{9}       : e.APTR;
  148.                                     password{10}  : ARRAY OF CHAR;
  149.                                     action{0}     : LONGINT):LONGINT;
  150.  
  151. PROCEDURE Decrunch* {CrMBase,-48} (source{8}      : e.APTR;
  152.                                    dest{9}        : e.APTR;
  153.                                    DataHeader{10} : DataHeader):e.APTR;
  154.  
  155. PROCEDURE ProcessCrunchStructA* {CrMBase,-66} (crunchstruct{9} : CrunchStructPtr;
  156.                                                action{0}       : LONGINT;
  157.                                                taglist{8}      : ARRAY OF u.TagItem):CrunchStructPtr;
  158.  
  159. PROCEDURE ProcessCrunchStructTags* {CrMBase,-66} (crunchstruct{9} : CrunchStructPtr;
  160.                                                   action{0}       : LONGINT;
  161.                                                   tag1{8}.. : u.Tag):CrunchStructPtr;
  162.  
  163. PROCEDURE ProcessPW* {CrMBase,-54} (password{8} : ARRAY OF CHAR;
  164.                                     action{0}   : LONGINT):LONGINT;
  165.  
  166. PROCEDURE AllocCrunchStructA* {CrMBase,-78}(taglist{8} : ARRAY OF u.TagItem):CrunchStructPtr;
  167.  
  168. PROCEDURE AllocCrunchStructTags*{CrMBase,-78}(tag1{8}.. : u.Tag):CrunchStructPtr;
  169.  
  170. PROCEDURE FreeCrunchStruct*{CrMBase,-84}(crunchstruct{8}:CrunchStructPtr);
  171.  
  172. (* oberon support procedures *)
  173.  
  174. (* $RangeChk- $StackChk- $OvflChk- *)
  175.  
  176. PROCEDURE InitCrunchStruct*(cs             : CrunchStructPtr;
  177.                             src,dest       : e.APTR;
  178.                             srclen,destlen : LONGINT);
  179. BEGIN
  180.   IF cs#NIL THEN
  181.     cs^.Src:=src;
  182.     cs^.SrcLen:=srclen;
  183.     cs^.Dest:=dest;
  184.     cs^.DestLen:=destlen;
  185.   END;
  186. END InitCrunchStruct;
  187.  
  188. BEGIN
  189.   CrMBase:=e.OpenLibrary(CrMName,CrMVersion);
  190.   IF CrMBase = NIL THEN
  191.     IF i.DisplayAlert(i.recoveryAlert,
  192.                       "\x00\x64\x14missing crm.library V4\o\o",50) THEN END;
  193.     HALT(20);
  194.   END;
  195. CLOSE
  196.  IF CrMBase # NIL THEN
  197.    e.CloseLibrary(CrMBase);
  198.    CrMBase:=NIL;
  199.  END;
  200. END CrM.
  201.  
  202.